<?php
/**
 * Created by PhpStorm.
 * User: hjc19850430@gmail.com
 * Date: 2016/7/11
 * Time: 14:55
 * FileName: BaseError.class.php
 * ProjectName: greencamps
 */
Abstract class BaseError
{
    /**
     * 错误消息数组
     * @var array
     */
    protected $errMsgArr = array();


    /**
     * 获得错误消息在子类中必须要实现
     * @return mixed
     */
    abstract protected function getErrMsg();


    /**
     * 将错误消息设置给属性errMsgArr
     */
    public function __construct()
    {
        $this->errMsgArr = $this->getErrMsg();
    }

    /**
     * 通过错误代码匹配到错误信息,在子类中必须实现
     * @param string $errCode 错误代码
     * @param mixed $data 数据
     * @return mixed
     */
     public function returnErrResult($errCode, $data = null)
     {
         $returnData = array(
             'code' => $errCode,
             'msg' => $this->errMsgArr[$errCode],
             'data' => $data
         );

         return $returnData;
     }


    /**
     * 返回中奖成功后的消息
     * @param int $code 成功后的code
     * @param string $msg   成功消息
     * @param null $data
     * @return array
     */
    public function returnSuccResult($code=200, $msg='success', $data = null)
    {
        return array(
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        );
    }
}